/*!
 *  Login to sf
 */
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;


// user name
var user = Environment.UserName;
//var user = "I069498";

// certificate
var store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadWrite);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName, user, false);
var cc = certs[0];

// request
var request = WebRequest.CreateHttp("https://accounts.sap.com/saml2/idp/usso/sap?sp=www.successfactors.com");
request.ClientCertificates.Add(cc);

// response
var response = request.GetResponse();
var sb = new StringBuilder();
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
	sb.Append("{\"cookie\":\"");
	sb.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(response.Headers["Set-Cookie"])));
	sb.Append("\",\"html\":\"");
    sb.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(reader.ReadToEnd())));
    sb.Append("\"}");
}

Console.Write(sb.ToString());